home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / transmission / web / javascript / dialog.js < prev    next >
Encoding:
JavaScript  |  2009-03-30  |  4.3 KB  |  148 lines

  1. /*
  2.  *    Copyright ¬© Dave Perrett and Malcolm Jarvis
  3.  *    This code is licensed under the GPL version 2.
  4.  *    For more details, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  5.  *
  6.  * Class Dialog
  7.  */
  8.  
  9. function Dialog(){
  10.     this.initialize();
  11. }
  12.  
  13. Dialog.prototype = {
  14.  
  15.     /*
  16.      * Constructor
  17.      */
  18.     initialize: function() {
  19.         
  20.         /*
  21.          * Private Interface Variables
  22.          */
  23.         this._container = $('#dialog_container');
  24.         this._heading = $('#dialog_heading');
  25.         this._message = $('#dialog_message');
  26.         this._cancel_button = $('#dialog_cancel_button');
  27.         this._confirm_button = $('#dialog_confirm_button');
  28.         this._callback_function = '';
  29.         this._callback_data = null;
  30.         
  31.         // Observe the buttons
  32.         this._cancel_button.bind('click', {dialog: this}, this.onCancelClicked );
  33.         this._confirm_button.bind('click', {dialog: this}, this.onConfirmClicked );
  34.     },
  35.  
  36.  
  37.  
  38.  
  39.     
  40.     /*--------------------------------------------
  41.      * 
  42.      *  E V E N T   F U N C T I O N S
  43.      * 
  44.      *--------------------------------------------*/
  45.  
  46.     hideDialog: function( )
  47.     {
  48.         $('body.dialog_showing').removeClass('dialog_showing');
  49.         if (Safari3) {
  50.             $('div#dialog_container div.dialog_window').css('top', '-150px');
  51.             setTimeout("dialog._container.hide();",500);
  52.         } else {
  53.             this._container.hide();
  54.             transmission.hideiPhoneAddressbar();
  55.         }
  56.         transmission.updateButtonStates();
  57.     },
  58.  
  59.     onCancelClicked: function( event )
  60.     {
  61.         event.data.dialog.hideDialog( );
  62.     },
  63.  
  64.     onConfirmClicked: function( event )
  65.     {
  66.         var dialog = event.data.dialog;
  67.         eval( dialog._callback_function + "(dialog._callback_data)" );
  68.         dialog.hideDialog( );
  69.     },
  70.  
  71.     /*--------------------------------------------
  72.      * 
  73.      *  I N T E R F A C E   F U N C T I O N S
  74.      * 
  75.      *--------------------------------------------*/
  76.     
  77.     /*
  78.      * Display a confirm dialog
  79.      */
  80.     confirm: function(dialog_heading, dialog_message, confirm_button_label, callback_function, callback_data, cancel_button_label) {
  81.         if (!iPhone && Safari3) {
  82.             $('div#upload_container div.dialog_window').css('top', '-205px');
  83.             $('div#prefs_container div.dialog_window').css('top', '-425px');
  84.             setTimeout("$('#upload_container').hide();",500);
  85.             setTimeout("$('#prefs_container').hide();",500);
  86.         } else if (!iPhone) {
  87.             $('.dialog_container').hide();
  88.         }
  89.         setInnerHTML( this._heading[0], dialog_heading );
  90.         setInnerHTML( this._message[0], dialog_message );
  91.         setInnerHTML( this._cancel_button[0], (cancel_button_label == null) ? 'Cancel' : cancel_button_label );
  92.         setInnerHTML( this._confirm_button[0], confirm_button_label );
  93.         this._confirm_button.show();
  94.         this._callback_function = callback_function;
  95.         this._callback_data = callback_data;
  96.         $('body').addClass('dialog_showing');
  97.         this._container.show();
  98.         transmission.updateButtonStates();
  99.         if (iPhone) {
  100.             transmission.hideiPhoneAddressbar();
  101.         } else if (Safari3) {
  102.             setTimeout("$('div#dialog_container div.dialog_window').css('top', '0px');",10);
  103.         }
  104.     },
  105.     
  106.     /*
  107.      * Display an alert dialog
  108.      */
  109.     alert: function(dialog_heading, dialog_message, cancel_button_label) {
  110.         if (!iPhone && Safari3) {
  111.             $('div#upload_container div.dialog_window').css('top', '-205px');
  112.             $('div#prefs_container div.dialog_window').css('top', '-425px');
  113.             setTimeout("$('#upload_container').hide();",500);
  114.             setTimeout("$('#prefs_container').hide();",500);
  115.         } else if (!iPhone) {
  116.             $('.dialog_container').hide();
  117.         }
  118.         setInnerHTML( this._heading[0], dialog_heading );
  119.         setInnerHTML( this._message[0], dialog_message );
  120.         // jquery::hide() doesn't work here in Safari for some odd reason
  121.         this._confirm_button.css('display', 'none');
  122.         setInnerHTML( this._cancel_button[0], cancel_button_label );
  123.         // Just in case
  124.         if (!iPhone && Safari3) {
  125.             $('div#upload_container div.dialog_window').css('top', '-205px');
  126.             setTimeout("$('#upload_container').hide();",500);
  127.         } else {
  128.             $('#upload_container').hide();
  129.         }
  130.         $('body').addClass('dialog_showing');
  131.         transmission.updateButtonStates();
  132.         if (iPhone) {
  133.             transmission.hideiPhoneAddressbar();
  134.             this._container.show();
  135.         } else if (Safari3) {
  136.             // long pause as we just hid all the dialogs on a timeout - we'll get the error
  137.             // scrolling in and immediately disappearing if we're not careful!
  138.             //dialogTimeout = null;
  139.             this._container.show();
  140.             setTimeout("$('div#dialog_container div.dialog_window').css('top', '0px');",500);
  141.         } else {
  142.             this._container.show();
  143.         }
  144.     }
  145.     
  146.  
  147. }
  148.